﻿using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Model;
using Model.View;

namespace Utils.UserHelper;

public class FindMemoryUser
{
    public static async Task<ViewUser?> FindHistoryMemoryUser()
    {
        await using var db = new DataDbContent();
        var memory = await db.LoginMemory!.FirstOrDefaultAsync(e => e.IsUsing == "use");
        if (memory is null)
        {
            return null;
        }

        var res = new ViewUser
        {
            Account = memory.Account
        };
        if (memory.IsMemory)
        {
            res.Password = memory.Password;
        }
        res.Memory = memory.IsMemory;
        return res;
    }
}